package mission011;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Admin
 * @create 2019/10/23
 * @since 1.0.0
 */
public class Student {
  private String name;
    private int age;
    private int score;
    private String classNum;//表示学生的班号，例如“class05”

//    public int avg() {
//        return getScore()+getScore();
//        }
        public Student(String name,int age,int score,String classNum){
        this.name=name;
        this.age=age;
        this.score=score;
        this.classNum=classNum;
        }
        public String getName() {
            return name;
        }

        public int  getAge() {
            return age;
        }

        public int getScore() {
            return score;
        }

        public String getClassNum() {
            return classNum;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public void setScore(int score) {
            this.score = score;
        }

        public void setClassNum(String classNum) {
            this.classNum = classNum;
        }
    public static void main(String[] args) {
        List list= new ArrayList();
        list.add(new Student("Tom",18,100,"class05"));
        list.add(new Student("Jerry", 22, 70, "class04"));
        list.add(new Student("Owen", 25, 90, "class05"));
        list.add(new Student("Jim", 30,80 , "class05"));
        list.add(new Student("Steve", 28, 66, "class06"));
        list.add(new Student("Kevin", 24, 100, "class04"));
       double sumAge=0;
       double sumScore1=0;
       double sumScore2=0;
       double sumScore3=0;
       int a=0,b=0,c=0;
        for(Object i: list){
            Student s=(Student)i;
            sumAge+=s.getAge();
                if(s.getClassNum().equals("class04")){
              sumScore1+=s.getScore();
                    a++;
            }
            else if(s.getClassNum().equals("class05")){
                sumScore2+=s.getScore();
                    b++;
                }
            else if(s.getClassNum().equals("class06")){
                sumScore3+=s.getScore();
                    c++;
                }
        }
        System.out.println("学生的平均年龄"+sumAge/list.size());
        System.out.println("4班的平均成绩是"+sumScore1/a);
        System.out.println("5班的平均成绩是"+sumScore2/b);
        System.out.println("6班的平均成绩是"+sumScore3/c);
    }
}


